var namePrefix = "ghdskl";
function displaySignUp() {
    document.getElementById("username").style.display = "";
    document.getElementById("usermail").style.display = "";
    document.getElementById("userpassword").style.display = "";
    document.getElementById("passwordagain").style.display = "";
    document.getElementById("signupsubmit").style.display = "";
    var label = document.getElementById("label")
    if (label.value) label.style.display = "";
    document.getElementById("loginsubmit").style.display = "none";
    document.getElementById("loginname").style.display = "none";
    document.getElementById("loginpassword").style.display = "none";
    $(document).keyup(function (event) {
        if (event.keyCode == '13') {
            document.getElementById("signupsubmit").click();
        }
    });
}
function displayLogin() {
    document.getElementById("username").style.display = "none";
    document.getElementById("usermail").style.display = "none";
    document.getElementById("userpassword").style.display = "none";
    document.getElementById("passwordagain").style.display = "none";
    document.getElementById("signupsubmit").style.display = "none";
    document.getElementById("label").style.display = "none";
    document.getElementById("loginsubmit").style.display = "";
    document.getElementById("loginname").style.display = "";
    document.getElementById("loginpassword").style.display = "";
    $(document).keyup(function (event) {
        if (event.keyCode == '13') {
            document.getElementById("loginsubmit").click();
        }
    });
}
function signUpSubmit() {
    // alert(1);
    // if(localStorage.db==null)localStorage.db=[];
    var userName = document.getElementById("username").value;
    if (userName == '') {
        document.getElementById("username").setCustomValidity("请输入用户名");
        return;
    }
    else if (localStorage.getItem(namePrefix + userName)) {
        document.getElementById("username").setCustomValidity("用户名已存在！");
        return;
    }
    else {
        document.getElementById("username").setCustomValidity("");
    }
    if (!document.getElementById("usermail").checkValidity()) {
        return;
    }
    if (document.getElementById("userpassword").value.length < 6) {
        document.getElementById("userpassword").setCustomValidity("密码长度不少于六位！");
        return;
    }
    else {
        document.getElementById("userpassword").setCustomValidity("")
    }
    var passwd1 = document.getElementById("userpassword").value;
    var passwd2 = document.getElementById("passwordagain").value;
    if (passwd1 != passwd2) {
        document.getElementById("passwordagain").setCustomValidity("两次密码输入不一致!");
        return;
    }
    localStorage.setItem(namePrefix + userName, passwd1);
    localStorage.presentUser = userName;
    self.location = "./login_success.html";

    //            alert("heh");
}
function LoginSubmit() {
    var userName = document.getElementById("loginname").value;
    var passwd = document.getElementById("loginpassword").value;
    if (localStorage.getItem(namePrefix + userName) != passwd) {
        alert("用户名或密码错误！");
        return;
    }
    localStorage.presentUser = userName;
    self.location = "./login_success.html";
}
function setLabel() {
    // alert(1);
    var regxs = [];
    regxs.push(/[a-z]/g);
    regxs.push(/[0-9]/g);
    regxs.push(/(.[^a-z0-9])/g);
    var val = document.getElementById("userpassword").value;
    var len = val.length;
    var sec = 0;
    if (len >= 6) { // 至少六个字符
        for (var i = 0; i < regxs.length; i++) {
            if (val.match(regxs[i])) {
                sec++;
            }
        }
    }
    console.log(sec);
    var label = document.getElementById("label");
    if (val) {
        label.style.display = '';
    }
    else {
        label.style.display = 'none';
    }
    if (sec <= 1) label.innerHTML = "密码强度：弱";
    if (sec == 2) label.innerHTML = "密码强度：中";
    if (sec >= 3) label.innerHTML = "密码强度：强";
}
function checkUserName() { }
function checkPassword() { }
